#include "CAdvDisplayIndexSection.h"

CAdvDisplayIndexSection::CAdvDisplayIndexSection(void):IAdvSectionData(ADV_DISPLAY_INDEX_SECTION_TABLE_ID)
{
}

CAdvDisplayIndexSection::~CAdvDisplayIndexSection(void)
{ 
	list<DisplayIndex*>::iterator itDisplayIndex; 
	for (itDisplayIndex=m_displayIndexList.begin(); itDisplayIndex!=m_displayIndexList.end();itDisplayIndex++)
	{ 
		DisplayIndex* displayIndexInfo = (DisplayIndex*)*itDisplayIndex;  
		 
		list<AdvDiscriptor*>::iterator itAdvDiscriptor; 
		for (itAdvDiscriptor=displayIndexInfo->advDiscriptorList.begin(); itAdvDiscriptor!=displayIndexInfo->advDiscriptorList.end();itAdvDiscriptor++)
		{
			AdvDiscriptor* advDiscriptorInfo = (AdvDiscriptor*) *itAdvDiscriptor; 
			 if (advDiscriptorInfo)
			 {
				 delete advDiscriptorInfo;
			 }
		}
		if (displayIndexInfo)
		{
			delete displayIndexInfo;
		}
	} 
}


int CAdvDisplayIndexSection::GetLen() 
{
	int len = 0;
	list<DisplayIndex*>::iterator itDisplayIndex; 
	for (itDisplayIndex=m_displayIndexList.begin(); itDisplayIndex!=m_displayIndexList.end();itDisplayIndex++)
	{
		DisplayIndex* displayIndexInfo = (DisplayIndex*)*itDisplayIndex;  
		len += displayIndexInfo->TotalLen();
	}
	return len ;
}
void CAdvDisplayIndexSection::GetData(BYTE* buff  , int &len,int slotId)
{
}

 int CAdvDisplayIndexSection::GetLen(int slotId) 
 {
	 return 0;
 }

void CAdvDisplayIndexSection::GetData(BYTE* buff  , int &len)
{
	CBuffer stBuffer(buff, SECTION_MAXLEN);  
	int lenPosition = GetLen() ; 
	stBuffer.Write((WORD)lenPosition); 
	list<DisplayIndex*>::iterator itDisplayIndex; 
	for (itDisplayIndex=m_displayIndexList.begin(); itDisplayIndex!=m_displayIndexList.end();itDisplayIndex++)
	{ 
		DisplayIndex* displayIndexInfo = (DisplayIndex*)*itDisplayIndex;  
		int lenPeriod = displayIndexInfo->LoopLen();  
		stBuffer.Write((WORD)displayIndexInfo->display_index); 
		stBuffer.Write((WORD)displayIndexInfo->element_id); 
		//stBuffer.Write((BYTE)displayIndexInfo->reserved); 
		stBuffer.Write((BYTE)0xFF); 
		stBuffer.Write((BYTE)displayIndexInfo->visible); 
		stBuffer.Write((WORD)lenPeriod); 
		list<AdvDiscriptor*>::iterator itAdvDiscriptor; 
		for (itAdvDiscriptor=displayIndexInfo->advDiscriptorList.begin(); itAdvDiscriptor!=displayIndexInfo->advDiscriptorList.end();itAdvDiscriptor++)
		{
			AdvDiscriptor* advDiscriptorInfo = (AdvDiscriptor*) *itAdvDiscriptor; 
			unsigned char buff[512]={0};
			int len = 0;
			advDiscriptorInfo->GetDiscriptorData(buff,len);  
			stBuffer.Write((PBYTE)buff,len);   
		}
	} 
	len = lenPosition + 2;
}